package com.abcdefg.webpagechatprojectbymyself.api;

import com.abcdefg.webpagechatprojectbymyself.mapper.FriendMapper;
import com.abcdefg.webpagechatprojectbymyself.model.Friend;
import com.abcdefg.webpagechatprojectbymyself.model.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/FriendApi")
public class FriendApi {
    @Autowired
    private FriendMapper friendMapper;

    //获取好友列表
    @GetMapping("getFriendList")
    public Object  getFriendList(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session == null) {
            System.out.println("获取不到当前Session对象！！！");
            return new ArrayList<Friend>();
        }
        User user = (User) session.getAttribute("user");
        if(user == null) {
            System.out.println("获取不到当前user对象！！！");
            return new ArrayList<Friend>();
        }
        List<Friend> friendList=friendMapper.selectFriendListByUserId(user.getUserId());
        return friendList;
    }
}
